#include "OneObjEnvRenderer.hpp"

namespace zzz {
void OneObjEnvRenderer::AfterOnSize(unsigned int nType, int cx, int cy)
{
  camera_.OnSize(nType, cx, cy);
  objArcBall_.OnSize(nType, cx, cy);
  envArcBall_.OnSize(nType, cx, cy);
}

void OneObjEnvRenderer::DrawObj()
{
  glColor3f(1.0,1.0,1.0);
  glBegin(GL_QUADS);
  glVertex3d(-1,-1,0);
  glVertex3d(1,-1,0);
  glVertex3d(1,1,0);
  glVertex3d(-1,1,0);
  glEnd();
}

void OneObjEnvRenderer::SetupCamera()
{
  camera_.ApplyGL();
  objArcBall_.ApplyGL();
}

OneObjEnvRenderer::OneObjEnvRenderer()
{
  pCurObjArcBall_=&objArcBall_;
  pCurEnvArcBall_=&envArcBall_;
}

void OneObjEnvRenderer::OnLButtonDown(unsigned int nFlags,int x,int y)
{
  if (!lockArcBall_) {
    objArcBall_.OnLButtonDown(nFlags, x, y);
    envArcBall_.OnLButtonDown(nFlags, x, y);
  }
}

void OneObjEnvRenderer::OnLButtonUp(unsigned int nFlags,int x,int y)
{
  objArcBall_.OnLButtonUp(nFlags, x, y);
  envArcBall_.OnLButtonUp(nFlags, x, y);
}

void OneObjEnvRenderer::OnRButtonDown(unsigned int nFlags,int x,int y)
{
  if (!lockArcBall_) {
    envArcBall_.OnLButtonDown(nFlags, x, y);
  }
}

void OneObjEnvRenderer::OnRButtonUp(unsigned int nFlags,int x,int y)
{
  envArcBall_.OnLButtonUp(nFlags, x, y);
}

void OneObjEnvRenderer::OnMButtonDown(unsigned int nFlags,int x,int y)
{
  if (!lockArcBall_) {
    objArcBall_.OnLButtonDown(nFlags, x, y);
  }
}

void OneObjEnvRenderer::OnMButtonUp(unsigned int nFlags,int x,int y)
{
  objArcBall_.OnLButtonUp(nFlags, x, y);
}

void OneObjEnvRenderer::OnMouseMove(unsigned int nFlags,int x,int y)
{
  if (!lockArcBall_) {
    objArcBall_.OnMouseMove(nFlags, x, y);
    envArcBall_.OnMouseMove(nFlags, x, y);
    Redraw();
  }
}

void OneObjEnvRenderer::ResetArcball()
{
  objArcBall_.Reset();
  envArcBall_.Reset();
}

bool OneObjEnvRenderer::InitData()
{
  envArcBall_.Init(this);
  objArcBall_.Init(this);
  return ArcBallRenderer::InitData();
}

}